package com.lg.algorithm.collections.queue.block;

import lombok.SneakyThrows;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

/**
 SynchronousQueue
 无法指定大小，里面只有一个元素
 初期元素为null
 使用LockSupport.park进行阻塞

 */
public class SynchronizedQueueTest {
    @SneakyThrows
    public static void main(String[] args) {
        SynchronousQueue<Integer> integers = new SynchronousQueue<>();


        Thread thread = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(13);
                System.out.println("main start take");
                System.out.println(integers.take());
            } catch (Exception e) {
            }

        });
        thread.start();

        integers.put(1);

    }
}
